package com.zycx.system.menu.controller;

import com.zycx.system.menu.entity.Menu;
import com.zycx.system.menu.service.MenuService;
import com.zycx.common.page.ServerResponseTable;
import com.zycx.common.result.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Description:
 * Created by zycx on 2018-12-10 21:39
 * Created with IntelliJ IDEA.
 */
@RestController
@RequestMapping("/api/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("list")
    public ServerResponseTable page(@RequestParam Map<String, Object> params) {
        return menuService.page(params);
    }

    /**
     * 添加菜单
     *
     * @param menu 菜单实体
     * @return 菜单
     */
    @PostMapping("")
    public ServerResponse saveMenu(@RequestBody Menu menu) {
        return menuService.saveMenu(menu);
    }

    /**
     * 根据id查询
     *
     * @param id id
     * @return 对象
     */
    @GetMapping("/{id}")
    public ServerResponse getMenu(@PathVariable("id") String id) {
        return menuService.getMenu(id);
    }

    /**
     * 修改菜单
     *
     * @param menu 菜单
     * @return 菜单
     */
    @PutMapping("/{id}")
    public ServerResponse putMenu(@RequestBody Menu menu) {
        return menuService.putMenu(menu);
    }

    /**
     * 删除菜单  假删除
     *
     * @param id id
     * @return ..
     */
    @DeleteMapping("/{id}")
    public ServerResponse deleteMenu(@PathVariable("id") String id) {
        return menuService.deleteMenu(id);
    }


}
